/*
 * Description: 通信工具类。
 */
#ifndef GUEST_LINK_BASE
#define GUEST_LINK_BASE

#include <cstdint>
#include <vector>
#include "guest_socket.h"
#include "guest2host.pb.h"
#include "error.h"
#include "log.h"

namespace COMMON {
constexpr uint32_t MESSAGE_MAX_SIZE = 256 * 1024 * 1024;
class LinkBase {
public:
    static int SendMessage(const std::shared_ptr<MsgSock> &msgSock, MessageType type,
        const google::protobuf::MessageLite &message);
    static int ReceiveMessage(const std::shared_ptr<MsgSock> &msgSock, MessageType &type,
        std::vector<char> &messageBuffer, const uint32_t timeout = COMMON::OK);  // 接收超时 timeout 单位s
    static int PrintError();
    static void WaitTime(int time); // 等待ms
    static void SerializeAndResponse(const google::protobuf::MessageLite &msg, Guest::protobuf::link::Result &res);
private:
    static int ReadBuffer(const std::shared_ptr<MsgSock> &msgSock, std::vector<char> &buffer,
        const uint32_t timeout = COMMON::OK);
};
}
#endif // GUEST_LINK_BASE